home *** CD-ROM | disk | FTP | other *** search
/ IRIX Installation Tools & Overlays 2002 November / SGI IRIX Installation Tools & Overlays 2002 November - Disc 4.iso / dist / cluster_admin.idb / var / cluster / ha / diags / IP_address.pl.z / IP_address.pl
Perl Script  |  2002-10-15  |  7KB  |  203 lines

  1. #!/usr/sbin/perl
  2. #                                                                         
  3. #  Copyright (C) 1998, Silicon Graphics, Inc.                             
  4. #  All Rights Reserved.                                                   
  5. #                                                                         
  6. #  UNPUBLISHED -- Rights reserved under the copyright laws of the United  
  7. #  States.  Use of a copyright notice is precautionary only and does not  
  8. #  imply publication or disclosure.                                       
  9. #                                                                         
  10. #  THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF     
  11. #  SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR 
  12. #  DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN    
  13. #  PERMISSION OF SILICON GRAPHICS, INC.                                   
  14. #                                                                         
  15. #  U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND                               
  16. #  Use, duplication or disclosure by the Government is subject to         
  17. #  restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph       
  18. #  (c)(1)(ii) of the Rights in Technical Data and Computer Software       
  19. #  clause at DFARS 252.227-7013 and/or in similar or successor clauses    
  20. #  in the FAR, or the DOD or NASA FAR Supplement.  Unpublished-- rights   
  21. #  reserved under the copyright laws of the United States.                
  22. #  Contractor/manufacturer is Silicon Graphics, Inc.,                     
  23. #  2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.                 
  24. #
  25.  
  26. # IP_address
  27. #
  28. # Get all resources for a particular type 
  29. # and run the tests against that resource.
  30.  
  31. require "$LibDiagsPath/constants.pl";
  32. require "$LibDiagsPath/libdiags.pl";
  33. require "$LibDiagsPath/recurse.pl";
  34.  
  35. use Socket;
  36.  
  37. sub IP_address {
  38.   local ($machine_name, $resource) = @_;
  39.   local ($this);
  40.   local (@list);
  41.   local ($retv);
  42.  
  43.   &LogEntry();
  44.   &Verbose("Running resource type %s tests on node %s",
  45.        $IP_ADDRESS,$machine_name);
  46.  
  47.   if ($resource eq "ALL") {
  48.     @list=&GetResFromResType($machine_name,$IP_ADDRESS);
  49.     if (scalar(@list) < 1) {
  50.       &Failure("No resources found for resource type %s",$IP_ADDRESS);
  51.       return $CD_FAILURE;
  52.     }
  53.     foreach $this (@list) {
  54.       $retv=&TestIPaddress($machine_name,$this);
  55.  
  56.       # If the DESTRUCTIVE flag is set ...
  57.       if ($DESTRUCTIVE) {
  58.       if (&ExecIPaddress($machine_name,$this) == $CD_FAILURE) {
  59.           &Failure("Resource %s of resource type %s failed",$this,
  60.                $IP_ADDRESS);
  61.           $retv=$CD_FAILURE;
  62.       }
  63.       }
  64.       &ExitStatus($retv);
  65.     }
  66.   } else {
  67.     # We have been given the resource name.
  68.     $retv=&TestIPaddress($machine_name, $resource);
  69.  
  70.     # If the DESTRUCTIVE flag is set ...
  71.     if ($DESTRUCTIVE) {
  72.     if (&ExecIPaddress($machine_name,$resource) == $CD_FAILURE) {
  73.         &Failure("Resource %s of resource type %s failed",$resource,
  74.              $IP_ADDRESS);
  75.         $retv=$CD_FAILURE;
  76.     }
  77.     }
  78.     &ExitStatus($retv);
  79.   }
  80.   return $retv;
  81. }
  82.  
  83. # ExecIPaddress
  84. #    execute the resource scripts in order.
  85. #    1) probe
  86. #    2) exclusive
  87. #    3) start
  88. #    4) monitor
  89. #    5) stop
  90. #
  91. sub ExecIPaddress {
  92.     local ($node, $resource) = @_;
  93.     local ($retv);
  94.  
  95.     &LogEntry();
  96.  
  97.     &Status("Starting resource %s of resource type %s on node %s",
  98.          $resource,$IP_ADDRESS,$node);
  99.     
  100.     # Only execute the destructive tests on this node.
  101.     if (!&OnTheSameNode($node)) {
  102.        &Notice("Can only execute the resource destructive tests on local host");
  103.        &Log("Can only execute the resource destructive tests on local host %s/%s",
  104.           $this_host, $NodeToHost{$node});
  105.        return $CD_SUCCESS;
  106.     }
  107.  
  108.     &Status("Executing the $IP_ADDRESS resource scripts, I.e. probe, exclusive, start, monitor and  stop");
  109.     &Status("Please be patient ...");
  110.     foreach $script (@HA_LIST) {
  111.     $retv=ExecuteScript($node,$resource,$IP_ADDRESS,$script);
  112.     if ($retv == 0) {
  113.         # script failed, exit
  114.         return $CD_FAILURE;
  115.     }
  116.     # Sleep a while
  117.     sleep(3);
  118.     }
  119.     return $CD_SUCCESS;
  120. }
  121.  
  122. # TestIPaddress
  123. # The resource test has three parts
  124. #   1) Check the resource parameters.
  125. #   2) If the resource has dependencies check them.
  126.  
  127. sub TestIPaddress {
  128.   local ($machine_name, $resource) = @_;
  129.   local ($retv);
  130.   local ($addr,$net,$ifname,$braodcast);
  131.   local (@parameters);
  132.   local ($hostname);
  133.  
  134.   $retv=$CD_SUCCESS;
  135.  
  136.   &LogEntry();
  137.   &Status("Testing resource %s of resource type %s on node %s",
  138.        $resource,$IP_ADDRESS,$machine_name);
  139.   
  140.   # Get the resource parameter set.
  141.   @parameters=&GetResParameters($machine_name,$IP_ADDRESS,$resource);
  142.   if (scalar(@parameters) < 1 ) {
  143.     &Failure("No parameters returned for resource %s of resource type %s",
  144.          $resource,$IP_ADDRESS);
  145.     return $CD_FAILURE;
  146.   }
  147.   if (@parameters[0] < 0){
  148.     &Failure("No parameters found for resource %s of resource type %s",
  149.          $resource,$IP_ADDRESS);
  150.     return $CD_FAILURE;
  151.   }
  152.  
  153.   if (($net=&pulloff("NetworkMask",@parameters)) eq "") {
  154.     &Failure("%s resource %s does not have the %s parameter set",
  155.          $IP_ADDRESS,$resource,"NetworkMask");
  156.     $retv=$CD_FAILURE;
  157.   }
  158.  
  159.   if (($broad=&pulloff("BroadcastAddress",@parameters)) eq "") {
  160.     &Failure("%s resource %s does not have the %s parameter set",
  161.          $IP_ADDRESS,$resource,"BroadcastAddress");
  162.     $retv=$CD_FAILURE;
  163.   }
  164.  
  165.   if (($ifname=&pulloff("interfaces",@parameters)) eq "") {
  166.     &Failure("%s resource %s does not have the %s parameter set",
  167.          $IP_ADDRESS,$resource,"interfaces");
  168.     $retv=$CD_FAILURE;
  169.   }
  170.  
  171.   if (!CheckIPSyntax($resource)) {
  172.     &Failure("Resource %s has invalid IP_Address syntax %s",
  173.          $resource,$resource);
  174.     $retv=$CD_FAILURE;
  175.   }
  176.   
  177.   if (!CheckIPSyntax($broad)) {
  178.     &Failure("Resource %s has invalid Broadcast syntax %s",
  179.          $resource,$broad);
  180.     $retv=$CD_FAILURE;
  181.   }
  182.   
  183.   if (!&CheckNetSyntax($net)) {
  184.     &Failure("Resource %s has invalid Network mask %s\nIt should be in hexadecimal notation. Example: 0xffffff00 is a valid Network mask.\n",
  185.          $resource,$net);
  186.     $retv=$CD_FAILURE;
  187.   }
  188.   
  189.   if (!&CheckInterface($machine, $ifname)) {
  190.     &Failure("Resource %s has unknown interface specification %s",
  191.          $resource,$ifname);
  192.     $retv=$CD_FAILURE;
  193.   }
  194.  
  195.   #Check that the ipaddress is valid and is known to the system
  196.   if (!($hostname=gethostbyname($resource,AF_INET))) {
  197.     &Failure("Invalid resource %s of resource type %s",$resource,$IP_ADDRESS);
  198.     $retv=$CD_FAILURE;
  199.   }
  200.  
  201.   return $retv;
  202. }
  203.